{extend name="../../admin/view/main"}

{block name="style"}{include file='qiyeagent/form-style'}{/block}

{block name='content'}
<style>
    .upload-image-box {
        width: 130px;
        height: 110px;
        border: 1px solid rgba(125, 125, 125, .1);
        background-size: cover;
    }
    .upload-file-box {
        width: 80px;
        height: 50px;
        border: 1px solid rgba(125, 125, 125, .1);
        background-size: cover;
    }


</style>
<div id="QiyeagentEditor" class="layui-clear nowrap padding-bottom-30">
    <div class="layui-card news-right">
        <div class="layui-card-body">
            <!--<form onsubmit="return false" data-auto="true" action="{:request()->url()}" method="post" class='layui-form layui-card' autocomplete="off">-->
            <form class="layui-form padding-20" role="form" name="qiyeagent" onsubmit="return false">


                <table width="100%">
                    <tr>
                        <td style="padding-right:20px;">
                            <label class="layui-form-item relative block">
                                <span class="color-green">班级名称</span>
                                <input maxlength="256" ng-model="item.name" required placeholder="请在这里输入班级名称" name='name' class="layui-input">
                            </label>
                        </td>
                        <td>
                            <label class="layui-form-item relative block">
                                <span class="color-green">班级人数</span>
                                <input maxlength="256" ng-model="item.num" placeholder="请在这里输入班级人数" name='num' class="layui-input">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-right:20px;">
                            <label class="layui-form-item relative block">
                                <span class="color-green">上课地点</span>
                                <input maxlength="64" ng-model="item.addr" required placeholder="请在这里输入上课地点" name='addr' class="layui-input">
                            </label>
                        </td>
                        <td>
                            <label class="layui-form-item relative block">
                                <span class="color-green">上课时间</span>
                                <input maxlength="64" data-date-range ng-model="item.time_str" required placeholder="请在这里输入培训时间" name='time_str' class="layui-input">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-right:20px;">
                            <label class="layui-form-item relative block">
                                <span class="color-green">联系人</span>
                                <input maxlength="64" ng-model="item.contact_man" placeholder="请在这里输入联系人" name='contact_man' class="layui-input">
                            </label>
                        </td>
                        <td>
                            <label class="layui-form-item relative block">
                                <span class="color-green">联系电话</span>
                                <input maxlength="64" ng-model="item.contact_phone" placeholder="请在这里输入报名时间" name='contact_phone' class="layui-input">
                            </label>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding-right:20px;">
                            <label class="layui-form-item relative block">
                                <span class="color-green">备注</span>
                                <input maxlength="64" ng-model="item.notes" placeholder="请在这里输入备注" name='notes' class="layui-input">
                            </label>
                        </td>
                        <td></td>
                    </tr>
                </table>
                <div class="layui-form-item text-center padding-top-30">
                    <input name="class_id" value="{$class_id}" type="hidden">
                    <button ng-click="submit()" type="button" class="layui-btn">保存信息</button>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}

{block name='script'}
<script>window.form.render()</script>
<script>


        require(['angular', 'ckeditor'], function () {

            /*layui.use(['form'], function () {
                var form = layui.form;
            });*/

        var editor;
        var $form = $('form[name="qiyeagent"]');
        var $vali = $form.vali().data('validate');

        var app = angular.module("QiyeagentEditor", []).run(callback);
        angular.bootstrap(document.getElementById(app.name), [app.name]);

        function callback($rootScope) {
            $rootScope.list = [];
            $rootScope.item = {};
            $.form.load('{:request()->url()}', {output: 'json'}, 'get', function (ret) {
                console.log(typeof ret);
                console.log(ret);
                return $rootScope.$apply(function () {
                    apply(ret.data || {});
                }), false;
            });
                function apply(qiye) {
                    if(qiye.id==undefined) qiye = {
                        name: '', phone: '', contacts: '',intro:'',time_str:'',addr: ''
                    };
                    $rootScope.item = qiye;
                    $('.layui-card-body.layui-hide').removeClass('layui-hide');
                    $rootScope.item.style = "background-image:url('" + $rootScope.item.logo + "')";
                }
            $rootScope.setItemValue = function (name, value) {
                $rootScope.item[name] = value;
                $rootScope.item.style = "background-image:url('" + $rootScope.item.logo + "')";
            };

            $rootScope.setItemValuel = function (name, value) {
                $rootScope.item[name] = value;
                $rootScope.item.style = "background-file:url('" + $rootScope.item.annex + "')";

            };

            $rootScope.upItem = function (index, $event) {
                $event.stopPropagation();
                var tmp = [], cur = $rootScope.list[index];
                if (index < 1) return false;
                for (var i in $rootScope.list) {
                    (parseInt(i) === parseInt(index) - 1) && tmp.push(cur);
                    (parseInt(i) !== parseInt(index)) && tmp.push($rootScope.list[i]);
                }
                apply(tmp);
            };
            $rootScope.dnItem = function (index, $event) {
                $event.stopPropagation();
                var tmp = [], cur = $rootScope.list[index];
                if (index > $rootScope.list.length - 2) return false;
                for (var i in $rootScope.list) {
                    (parseInt(i) !== parseInt(index)) && tmp.push($rootScope.list[i]);
                    (parseInt(i) === parseInt(index) + 1) && tmp.push(cur);
                }
                apply(tmp);
            };
            $rootScope.delItem = function (index, $event) {
                $event.stopPropagation();
                var list = $rootScope.list, temp = [];
                for (var i in list) (parseInt(i) !== parseInt(index)) && temp.push(list[i]);
                apply(temp);
            };
            $rootScope.submit = function () {
                $vali.checkAllInput();
                if ($form.find('.validate-error').size() > 0) {
                    return $.msg.tips('表单验证不成功，请输入需要的内容！');
                }

                var time_str = $('[name="time_str"]').val().split(" - ");
                var data = {
                    id: $rootScope.item.id,
                    name: $rootScope.item.name,
                    addr: $rootScope.item.addr,
                    contact_man: $rootScope.item.contact_man,
                    contact_phone: $rootScope.item.contact_phone,
                    notes: $rootScope.item.notes,
                    time_str: $rootScope.item.time_str,
                    class_id: $('[name="class_id"]').val(),
                    num: $rootScope.item.num,
                    start_at: time_str[0],
                    end_at: time_str[1],
                };
                $.form.load('{:request()->url()}', {data: data}, "post");
            };
        }

    });
</script>




{/block}